package br.com.vertigo.sgci.session;

import java.util.Arrays;
import java.util.List;

import org.jboss.seam.annotations.Name;
import org.jboss.seam.framework.EntityQuery;

import br.com.vertigo.sgci.entity.Cliente;

@Name("clienteList")
@SuppressWarnings(value = { "unchecked", "serial" })
public class ClienteList extends EntityQuery {

	private static final String[] RESTRICTIONS = { "lower(cliente.nome) like concat(lower(#{clienteList.cliente.nome}),'%') ", };

	private Cliente cliente = new Cliente();

	@Override
	public String getEjbql() {
		return "select cliente from Cliente cliente" + orderna();
	}

	@Override
	public Integer getMaxResults() {
		return 25;
	}
	
	public String orderna(){
		String inicial = " order by cliente.nome asc";
		if(getOrder() != null){
			inicial = "";
		}
		if(this.cliente.getNome() != null && !this.cliente.getNome().equals("")){
			inicial = "";
		}
		return inicial;
	}

	public Cliente getCliente() {
		return cliente;
	}

	@Override
	public List<String> getRestrictions() {
		return Arrays.asList(RESTRICTIONS);
	}

}
